package org.NooLab.itexx.app.controller;

import org.NooLab.itexx.ITexxWindowIntf;
import org.NooLab.itexx.app.controller.parser.HTMLParser;
import org.NooLab.itexx.retrieval.Page;
import org.NooLab.itexx.retrieval.PageIntf;
import org.NooLab.itexx.retrieval.google.GooglePreProc;





public class HtmlConsumer implements HtmlConsumerIntf{

	ITexxWindowIntf webBrowserApp ;
	private HTMLParser domparser;

	GooglePreProc googlePreProc ;
	private PageIntf page;
	
	// ========================================================================
	public HtmlConsumer(ITexxWindowIntf app) {
		
		webBrowserApp = app;
		
		googlePreProc = new GooglePreProc() ;
	}
	// ========================================================================
	
	
	@Override
	public void parseHtml(String pageStr, String contextURL) {
		// 
		domparser = new HTMLParser();
		
		pageStr = googlePreProc.performPPP(pageStr);
		
		domparser.parse(pageStr, contextURL);
		
		page = new Page();
	}


	@Override
	public void parseHtml(String pageStr) {
		
		page = new Page();
		
		domparser = new HTMLParser(page);
		domparser.parse(pageStr, "") ;
		
		
	}


	@Override
	public void parseHtml(PageIntf page) {
		// 
		
		this.page = page;
		domparser = new HTMLParser(page);
		domparser.parse() ;

		// not here:  page.setText("");
		// this has been already done inside the wrapping parser object!
	}


	@Override
	public PageIntf getPage() {
		// 
		return page;
	}

}
